//
//  LETeamPKTipView.m
//  LivePlayer
//
//  Created by 赵春浩 on 2019/1/21.
//

#import "LETeamPKTipView.h"
#import "UIView+WXAutoLayout.h"
#import "Masonry.h"

#define EnglishPkWidthScale 667

@interface LETeamPKTipView ()

@property (strong, nonatomic) UIImageView *bgImageView;
@property (strong, nonatomic) UILabel *titleLabel;
@property (strong, nonatomic) UIImageView *teamIconView;

@end

@implementation LETeamPKTipView

- (instancetype)init {
    self = [super init];
    if (self) {
        [self initSubViews];
    }
    return self;
}

- (void)initSubViews {
    
//    // 背景视图
//    UIImageView *bgImageView = [[UIImageView alloc] init];
//    [self addSubview:bgImageView];
//    self.bgImageView =  bgImageView;
//    // 加载图片
//    UIImage *image = [UIImage imageNamed:@"zhanduipk_toast_chidao_bg_normal"];
//    CGFloat top = 0;
//    CGFloat left = 150;
//    CGFloat bottom = 0;
//    CGFloat right = 70;
//    UIEdgeInsets edgeInsets = UIEdgeInsetsMake(top, left, bottom, right);
//    UIImageResizingMode mode = UIImageResizingModeStretch;
//    UIImage *newImage = [image resizableImageWithCapInsets:edgeInsets resizingMode:mode];
//    bgImageView.image = newImage;
//
//    // 标题视图
//    UILabel *titleLabel = [[UILabel alloc] init];
//    titleLabel.font = [UIFont fontWithName:@"FZY4JW--GB1-0" size:18];
//    titleLabel.textColor = [UIColor colorWithHexValue:0xFF5C00];
//    [self addSubview:titleLabel];
//    self.titleLabel =  titleLabel;
//
//    // 队伍icon
//    UIImageView *teamIconView = [[UIImageView alloc] init];
//    [self addSubview:teamIconView];
//    teamIconView.image = [UIImage imageNamed:@"livevideo_enteampk_benchangzhanduifenzu_01sweetheartkate_pic_normal"];
//    self.teamIconView =  teamIconView;
//
    self.backgroundColor = [UIColor redColor];
}

+ (void)showWithIconName:(NSString *)imgName teamName:(NSString *)teamName {
    UIWindow *win = [UIApplication sharedApplication].delegate.window;
    [self showInView:win iconName:imgName teamName:teamName duration:0];
}

+ (void)showWithIconName:(NSString *)imgName teamName:(NSString *)teamName duration:(NSTimeInterval)duration {
    UIWindow *win = [UIApplication sharedApplication].keyWindow;
    [self showInView:win iconName:imgName teamName:teamName duration:duration];
}

+ (void)showInView:(UIView *)inView iconName:(NSString *)imgName teamName:(NSString *)teamName duration:(NSTimeInterval)duration {
    LETeamPKTipView *tipView = nil;
    if (inView) {
        tipView = [[LETeamPKTipView alloc] init];
        [inView addSubview:tipView];
        
//        tipView.titleLabel.text = [NSString stringWithFormat:@"欢迎加入%@ Team",teamName];
//        tipView.titleLabel.text = @"欢迎加入 Msjddk Mdjud djdd的战队";
//        tipView.teamIconView.image = [UIImage imageNamed:imgName];
        
//        __weak typeof(tipView)tipViewWeak = tipView;
//        __weak typeof(inView)inViewWeak = inView;
//        CGFloat titleLM = 11;
//        CGFloat titleRM = 22;
//        CGFloat iconW = 42;
//        CGFloat iconH = 48;
//        CGFloat iconLM = 14;
        
//        [tipView.teamIconView mas_remakeConstraints:^(MASConstraintMaker *make) {
//            make.centerY.equalTo(tipViewWeak.mas_centerY);
//            make.width.offset(iconW);
//            make.height.offset(iconH);
//            make.left.offset(iconLM);
//        }];
//
//        [tipView.titleLabel  mas_remakeConstraints:^(MASConstraintMaker *make) {
//            make.left.equalTo(tipViewWeak.teamIconView.mas_right).offset(titleLM);
//            make.centerY.equalTo(tipViewWeak.mas_centerY);
//        }];
//
//        [tipView layoutIfNeeded];
//
//        CGFloat tipW = iconLM+iconW+titleLM+tipView.titleLabel.width+titleRM;//背景切图尺寸370x72
//        CGFloat tipH = 72;
//        [tipView mas_makeConstraints:^(MASConstraintMaker *make) {
//            make.top.offset(7);
//            make.centerX.equalTo(inViewWeak.mas_centerX);
//            make.width.offset(tipW);
//            make.height.offset(tipH);
//        }];
//
//        [tipView.bgImageView mas_remakeConstraints:^(MASConstraintMaker *make) {
//            make.top.left.bottom.right.offset(0);
//        }];
//
//        [tipView mas_makeConstraints:^(MASConstraintMaker *make) {
//            make.top.left.right.offset(0);
//            make.height.offset(100);
//        }];
        tipView.frame = CGRectMake(0, 0, 300, 100);
        tipView.backgroundColor = [UIColor redColor];
        if (duration > 0) {
            dispatch_after(dispatch_time(DISPATCH_TIME_NOW, (int64_t)(duration * NSEC_PER_SEC)), dispatch_get_main_queue(), ^{
                [tipView removeFromSuperview];
               // [tipView removeFromSuperview];
            });
        }
    }
}

- (void)dismiss {
    UIWindow *win = [UIApplication sharedApplication].delegate.window;
    for (LETeamPKTipView *view in win.subviews) {
        if ([view isKindOfClass:[LETeamPKTipView class]]) {
            [view removeFromSuperview];
        }
    }
}


@end
